#pragma strict
var speed : float;
var child1 : Texture;
var child2 : Texture;
var child3 : Texture;
var child4 : Texture;
var child4_2 : Texture;
var kikoCrying : AudioClip;
var randomTexture : float;
var splatParticle : ParticleSystem;
var particleMaterials : Texture[];

var isMoving : boolean = true;

function Start ()
{
	speed = 15;
}

function Update ()
{
	if (isMoving)
		transform.Translate(-speed * Time.deltaTime,0,0);
}

function Attacked ()
{
	splatParticle.renderer.material.mainTexture = particleMaterials[Random.Range (0, particleMaterials.length)];
	splatParticle.Play();
	if (renderer.material.mainTexture == child4)
	{
		renderer.material.mainTexture = child4_2;
		audio.PlayOneShot(kikoCrying);
		yield WaitForSeconds (0.2);
	}
	yield WaitForSeconds (0.2);

	randomTexture = Random.value;
	
	if (randomTexture < 0.3)
	{
		renderer.material.mainTexture = child1;
	}
	else if (randomTexture < 0.6)
	{
		renderer.material.mainTexture = child2;
	}
	else if (randomTexture < 0.9)
	{
		renderer.material.mainTexture = child3;
	}
	else
	{
		renderer.material.mainTexture = child4;
	}

	
	if (Random.Range(-1,1) < 0)
		transform.position.x = -20;
	else
		transform.position.x = 20;
	
	if (Random.Range(-1,1) < 0)
		speed *= -1;
		
	GoodHand.badThings ++;
}